package com.jkoa;

import able.stripes.AbleActionBean;
import com.jkoa.model.Pengguna;
import com.jkoa.stripes.config.JkoaActionBeanContext;
import net.sourceforge.stripes.action.SimpleMessage;
import net.sourceforge.stripes.validation.SimpleError;

public abstract class BaseActionBean extends AbleActionBean {

    //Default paging implementation - use in all pages
    Integer __pg_max_records = 10;
    Integer __pg_start = 0;
    Integer __pg_total_records = 0;    

    @Override
    public JkoaActionBeanContext getContext() {
        return (JkoaActionBeanContext) super.getContext();
    }   

    public Pengguna getUserId() {
        if(getContext() != null)
            if(getContext().getCurrentUser() != null)
                return getContext().getCurrentUser();
        return null;
    }
    
    public String getUserType() {
        if (getContext() != null) {
            if(getContext().getCurrentUser() != null)
                return getContext().getCurrentUser().getKodPguna().getKod();
        }
        return "";
    }

    public Boolean getLoggedIn() {
        return getContext().isLoggedIn();
    }

    public Integer get__pg_max_records() {
        return __pg_max_records;
    }

    public void set__pg_max_records(Integer __pg_max_records) {
        this.__pg_max_records = __pg_max_records;
    }

    public Integer get__pg_start() {
        return __pg_start;
    }

    public void set__pg_start(Integer __pg_start) {
        this.__pg_start = __pg_start;
    }

    public Integer get__pg_total_records() {
        return __pg_total_records;
    }

    public void set__pg_total_records(Integer __pg_total_records) {
        this.__pg_total_records = __pg_total_records;
    }  
    
    protected void addSimpleError(String msg){
		getContext().getValidationErrors().addGlobalError(
				new SimpleError(msg));		
	}
    
    protected void addSimpleMessage(String msg){
		getContext().getMessages().add(new SimpleMessage(msg));
	}
    
}
